import { createRouter, createWebHistory, createWebHashHistory, RouteRecordRaw } from 'vue-router';
import Home from '../views/Home.vue';

const routes: Array<RouteRecordRaw> = [
  // {
  //   path: '/home',
  //   name: 'Home',
  //   component: Home,
  // },
  //{ path: '/', redirect: '/patientList' },
  {
    path: '/about',
    name: 'About',
    component: () => import(/* webpackChunkName: "about" */ '../views/About.vue'),
  },

  {
    //就诊人列表
    path: '/patientList',
    name: 'patientList',
    component: () => import(/* webpackChunkName: "patientList" */ '../views/patientList.vue'),
    meta: {
      title: '就诊人列表',
    },
  },

  {
    //继续填写
    path: '/continue',
    name: 'continue',
    component: () => import(/* webpackChunkName: "continue" */ '../views/continue.vue'),
    meta: {
      title: '入院登记',
    },
  },
  {
    //开始登记
    path: '/startRegister',
    name: 'startRegister',
    component: () => import(/* webpackChunkName: "startRegister" */ '../views/startRegister.vue'),
    meta: {
      title: '入院登记',
    },
  },
  {
    //开始登记
    path: '/info',
    name: 'info',
    component: () => import(/* webpackChunkName: "info" */ '../views/info.vue'),
    meta: {
      title: '入院登记详情',
    },
  },
];

//process.env.BASE_URL
const router = createRouter({
  history: createWebHashHistory(),
  routes,
});

router.beforeEach((to, from, next) => {
  if (to.meta.title && typeof to.meta.title === 'string') {
    //判断是否有标题
    document.title = to.meta.title;
  }
  next();
});

export default router;
